import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p004 from './p004';
import p005 from './p005';

import format from '@dfeidao/atom-web/dt/format';
import get from '@dfeidao/atom-web/global/get';


export default async function a007(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	// 技术类模糊查询
	const dta = get('dta');
	const staff_n = dta.staff_no;

	const knowledge_name1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="t_word"]');
	const knowledge_nam = knowledge_name1.value;

	const res = await nodejs<{ res: Array<{ create_time: number }> }>('knowledge-base/zj-000001/s004', {
		filter: {
			knowledge_name: knowledge_nam,
			staff_no: staff_n
		}
	});
	const p = res.res.map((n) => {
		return {
			...n, create_time: format(n.create_time, 2)
		};
	});
	const dtsj = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p004"]');
	const dtmb = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p005"]');
	if (res.res.length > 0) {
		render(fd, p, p004, 'p004', 'inner');
		dtsj.style.display = 'block';
		dtmb.style.display = 'none';
	} else {
		render(fd, '', p005, 'p005', 'inner');
		dtmb.style.display = 'block';
		dtsj.style.display = 'none';
	}
}
